<!-- $Revision: 15370 $ $Date: 2013-05-22 15:55:57 -0300 (Wed, 22 May 2013) $ -->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:import href="../../../../../../lumis/doui/style/DouiControls.xsl"/>
	<xsl:output omit-xml-declaration = "yes" method="xml" />
	
	<xsl:template match="control[@type='lum_dropDownList' and contains(@id,'comboBandeira')]">
		<script>
			function buscarFilial(elm, elmSelecionado)
			{
				$.ajax({
					type:'POST',
					url:'millenium/jsp/buscarFilial.jsp?band='+elm.selectedOptions[0].value,
					dataType:'json',
					cache: 'true',
					success: function(data)
					{
						var elmFil = $('#comboFilial');
						
						elmFil.find('option').remove();
						
						elmFil.append(new Option("", "", true, true));
						
						for( j = 0; data.length <xsl:text disable-output-escaping="yes">></xsl:text> j; j++ )
						{
							var filiais = $.parseJSON(data[j]);
							var sel = false;
							if(elmSelecionado == filiais[0])
								sel = true;	
								
							elmFil.append(new Option(filiais[1], filiais[0], sel, sel));
						}
						
					}
				})
			}
			$(document).ready(function(){
				
				var filial      = "<xsl:value-of select="@id"/>";
				var elm         = document.getElementById(""+filial+"");
				buscarFilial(elm, document.getElementById('comboFilial').selectedOptions[0].value);
			});
		</script>
		<select onchange="buscarFilial(this)" name="{@id}">
			<xsl:apply-templates select="." mode="generateIdAttribute"><xsl:with-param name="id" select="@id"/></xsl:apply-templates>
			<xsl:apply-templates select="@*[name()!='type' and name()!='id' and name()!='optionsSourceId' and name()!='sourceId' and name()!='renderBlankOption' and name()!='disabled' and name()!='valueFieldId' and name()!='textFieldId']" />
			<xsl:if test="@disabled='true' or count(data/option)=0">
				<xsl:attribute name="disabled">disabled</xsl:attribute>
			</xsl:if>
			<xsl:for-each select="data/option">
				<option value="{value}">
					<xsl:if test="selected='true'">
						<xsl:attribute name="selected">selected</xsl:attribute>
					</xsl:if>
					<xsl:value-of select="text"/>
				</option>
			</xsl:for-each>
			<xsl:if test="count(data/option)=0">
				<option />
			</xsl:if>
		</select>
		<xsl:apply-templates select="control" />
	</xsl:template>
	
	</xsl:stylesheet>
